package cn.itsource.petHome.basic.service.impl;


import cn.itsource.petHome.basic.mapper.BaseMapper;
import cn.itsource.petHome.basic.query.BaseQuery;
import cn.itsource.petHome.basic.service.IBaseService;
import cn.itsource.petHome.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;

    @Override
    public List<T> loadAll() {
        return mapper.loadAll();
    }

    @Override
    public PageResult<T> queryByPage(BaseQuery q) {
        Long count = mapper.getCount(q);
        if(count.equals(0L)){
            return new PageResult<T>();
        }
        PageResult<T> result = new PageResult<>(count, mapper.highQuery(q));
        return result;
    }

    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public void save(T s) {
        mapper.save(s);
    }

    @Override
    public void update(T s) {
        mapper.update(s);
    }

    @Override
    public void batchDelete(Long[] ids) {
        mapper.batchDelete(ids);
    }
}
